package com.cskaoyan.controller.admin;

import com.cskaoyan.bean.bo.IssueCreateBo;
import com.cskaoyan.bean.entity.Issue;
import com.cskaoyan.bean.vo.BasePageData;
import com.cskaoyan.bean.vo.BaseParam;
import com.cskaoyan.bean.vo.BaseRespVo;
import com.cskaoyan.service.IssueService;
import com.cskaoyan.utils.BaseRespVoUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author break_a_leg
 * @description  通用问题
 * @date 2021年10月19日 19:46
 */
@RestController
@RequestMapping("admin/issue")
public class IssueController {

    @Autowired
    IssueService issueService;

    @RequestMapping("list")
    public BaseRespVo list(String question, BaseParam param) {
        BasePageData data = issueService.list(question,param);
        return BaseRespVo.ok(data);
    }

    @RequestMapping("create")
    public BaseRespVo create(@RequestBody IssueCreateBo issueCreateBo) {
        Issue issue = issueService.create(issueCreateBo);
        return BaseRespVo.ok(issue);
    }

    @RequestMapping("update")
    public BaseRespVo update(@RequestBody Issue issue) {
        Issue data = issueService.update(issue);
        return BaseRespVo.ok(data);
    }

    @RequestMapping("delete")
    public BaseRespVo delete(@RequestBody Issue issue) {
        int affectedRows = issueService.delete(issue);
        return BaseRespVoUtil.respByAffectedRow(affectedRows);
    }
}
